package com.itheima.server.controller;

import com.itheima.domain.Question;
import com.itheima.dto.RecommendUserDto;
import com.itheima.server.service.TanhuaService;
import com.itheima.vo.NearUserVo;
import com.itheima.vo.PageResult;
import com.itheima.vo.TodayBest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@RestController
@Slf4j
@RequestMapping("/tanhua")
public class TanhuaController {


    @Resource
    private TanhuaService tanhuaService;

    /**
     * 查询今日佳人
     * @return
     */
    @GetMapping("/todayBest")
    public ResponseEntity<TodayBest> todayBest(){
        TodayBest todayBest = tanhuaService.todayBest();
        return ResponseEntity.ok(todayBest);
    }


    /**
     * 推荐朋友
     * @param recommendUserDto
     * @return
     */
    @GetMapping("/recommendation")
    public ResponseEntity<PageResult> recommendation(RecommendUserDto recommendUserDto){
        PageResult pageResult = tanhuaService.recommendation(recommendUserDto);
        return ResponseEntity.ok(pageResult);
    }

    /**
     * 查看佳人信息
     * @param id
     * @return
     */
    @GetMapping("/{id}/personalInfo")
    public ResponseEntity<TodayBest> personalInfo(@PathVariable Long id){
        TodayBest todayBest = tanhuaService.personalInfo(id);
        return ResponseEntity.ok(todayBest);
    }

    /**
     * 获取陌生人问题
     * @param userId
     * @return
     */
    @GetMapping("/strangerQuestions")
    public ResponseEntity<String> strangerQuestions(Long userId){
        String question = tanhuaService.strangerQuestions(userId);
        return ResponseEntity.ok(question);
    }

    /**
     * 回复陌生人问题
     * @param map
     * @return
     */
    @PostMapping("/strangerQuestions")
    public ResponseEntity<String> strangerQuestion(@RequestBody Map map){
        long userId = Long.parseLong(map.get("userId").toString());
        String reply = map.get("reply").toString();
        tanhuaService.strangerQuestion(userId,reply);
        return ResponseEntity.ok("OK");
    }


    /**
     * 推荐列表查询
     * @return
     */
    @GetMapping("/cards")
    public ResponseEntity<List<TodayBest>> cards(){
        List<TodayBest> todayBests = tanhuaService.cards();
        return ResponseEntity.ok(todayBests);
    }

    /**
     * 喜欢
     * @param id
     * @return
     */
    @GetMapping("/{id}/love")
    public ResponseEntity<String> love(@PathVariable Long id){
        tanhuaService.love(id);
        return ResponseEntity.ok("OK");
    }


    /**
     * 不喜欢
     * @param id
     * @return
     */
    @GetMapping("/{id}/unlove")
    public ResponseEntity<String> unLove(@PathVariable Long id){
        tanhuaService.unLove(id);
        return ResponseEntity.ok("OK");
    }

    /**
     * 搜附近
     * @param gender
     * @param distance
     * @return
     */
    @GetMapping("/search")
    public ResponseEntity<List<NearUserVo>> search(String gender,@RequestParam(defaultValue = "2000") String distance){
        List<NearUserVo> vo = tanhuaService.search(gender,distance);
        return ResponseEntity.ok(vo);
    }



}
